package server.modules.generator.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import server.common.utils.PageUtils;
import server.common.utils.Query;

import server.modules.generator.dao.PointDao;
import server.modules.generator.entity.PointEntity;
import server.modules.generator.entity.ProjectEntity;
import server.modules.generator.service.PointService;
import server.common.utils.PageUtils;
import server.common.utils.Query;
import server.modules.generator.dao.PointDao;
import server.modules.generator.entity.PointEntity;
import server.modules.generator.service.PointService;
import server.modules.generator.service.ProjectService;
import server.modules.sys.entity.SysUserEntity;
import server.modules.sys.service.SysUserService;


@Service("pointService")
public class PointServiceImpl extends ServiceImpl<PointDao, PointEntity> implements PointService {
    @Autowired
    ProjectService projectService;
    @Autowired
    SysUserService sysUserService;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PointEntity> page = this.page(
                new Query<PointEntity>().getPage(params),
                new QueryWrapper<PointEntity>()
        );

        for (PointEntity sing : page.getRecords()) {
            ProjectEntity projectEntity = projectService.getById(sing.getProjectId());
            if (null != projectEntity)
                sing.setProjectName(projectEntity.getName());
            else
                sing.setProjectName("未配置");


            SysUserEntity sysUserEntity = sysUserService.getById(sing.getOwnerId());
            if (null != sysUserEntity)
                sing.setOwnerIdV(sysUserEntity.getShowname());
            else
                sing.setOwnerIdV("未配置");
            SysUserEntity diown = sysUserService.getById(sing.getDiyapeidianOwnerId());
            if (null != diown)
                sing.setDiyapeidianOwnerIdV(diown.getShowname());
            else
                sing.setDiyapeidianOwnerIdV("未配置");



            SysUserEntity guidao = sysUserService.getById(sing.getGuidaoOwnerId());
            if (null != guidao)
                sing.setGuidaoOwnerIdV(guidao.getShowname());
            else
                sing.setGuidaoOwnerIdV("未配置");


            SysUserEntity jianzhu = sysUserService.getById(sing.getJianzhuOwnerId());
            if (null != jianzhu)
                sing.setJianzhuOwnerIdV(jianzhu.getShowname());
            else
                sing.setJianzhuOwnerIdV("未配置");


            SysUserEntity jiegou = sysUserService.getById(sing.getJiegouOwnerId());
            if (null != jiegou)
                sing.setJiegouOwnerIdV(jiegou.getShowname());
            else
                sing.setJiegouOwnerIdV("未配置");


            SysUserEntity shenhe = sysUserService.getById(sing.getShenheOwnerId());
            if (null != shenhe)
                sing.setShenheOwnerIdV(sysUserEntity.getShowname());
            else
                sing.setShenheOwnerIdV("未配置");


            SysUserEntity tongfeng = sysUserService.getById(sing.getTongfengOwnerId());
            if (null != tongfeng)
                sing.setTongfengOwnerIdV(tongfeng.getShowname());
            else
                sing.setTongfengOwnerIdV("未配置");
        }


        return new PageUtils(page);
    }

}